package com.sw.small_world.application;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

import com.alibaba.mobileim.YWAPI;
import com.alibaba.mobileim.YWIMCore;
import com.alibaba.mobileim.YWIMKit;
import com.alibaba.wxlib.util.SysUtil;
import com.sw.small_world.openim.OpenImHelper;


/**
 * Created by zs on 2016/08/08.
 */
public class SWApplication extends Application {
    private static Context mContext;
    private static Handler mHandler;
    public static String APP_KEY = "23015524";
    private static YWIMKit iMKit;
    private static YWIMCore iMCore;


    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        mHandler = new Handler();
        initIM();
    }

    private void initIM() {
        //必须首先执行这部分代码, 如果在":TCMSSevice"进程中，无需进行云旺（OpenIM）和app业务的初始化，以节省内存;
        SysUtil.setApplication(this);
        if (SysUtil.isTCMSServiceProcess(this)) {
            return;
        }
        //第一个参数是Application Context
        //这里的APP_KEY即应用创建时申请的APP_KEY，同时初始化必须是在主进程中
        if (SysUtil.isMainProcess()) {
            YWAPI.init(this, APP_KEY);
        }
//        OpenImHelper.initCustom();
    }

    /**
     * 获取全局的context
     */
    public static Context getContext() {
        return mContext;
    }


    /**
     * 获取全局的主线程的handler
     */
    public static Handler getHandler() {
        return mHandler;
    }

    public static YWIMKit getiMKit() {
        return iMKit;
    }

    public static void setiMKit(YWIMKit iMKit) {
        SWApplication.iMKit = iMKit;
    }

    public static YWIMCore getiMCore() {
        return getiMKit().getIMCore();
    }
}
